
#include <stdio.h>
#include <string.h>
#include "interruptRegisters.h"
typedef unsigned int Uns32;
typedef unsigned int Uns8;

#include "interrupt.h"
#include "spr_defs.h"

#define LOG(_FMT, ...)  printf( "TEST INTERRUPT: " _FMT,  ## __VA_ARGS__)




static inline void writeReg32(Uns32 address, Uns32 offset, Uns32 value)
{
    *(volatile Uns32*) (address + offset) = value;
}


static inline Uns32 readReg32(Uns32 address, Uns32 offset)
{
    return *(volatile Uns32*) (address + offset);
}

static inline Uns8 readReg8(Uns8 address, Uns8 offset)
{
    return *(volatile Uns8*) (address + offset);
}


volatile static Uns32 interruptCount = 0;

void interruptHandler(void)
{
    LOG("Interrupt\n");
	LOG("Read register INTERRUPT_BASE + INTERRUPTER_C0_DATA_ADDR: 0x%x\n", readReg32(INTERRUPT_BASE, INTERRUPT_C0_DATA_ADDR));
}

int main(int argc, char **argv)
{
    //Attach the external interrupt handler for 'intr0'
    int_init();
    int_add(3, (void *)interruptHandler, NULL);
    int_enable(3);

    //Enable external interrupts
    Uns32 spr = MFSPR(17);
    spr |= 0x4;
    MTSPR(17, spr);

	while(1){ }
	
	return 1;
}

